package com.blkkj.huan.Controller;


import com.aliyuncs.iot.model.v20170420.ApplyDeviceWithNamesRequest;
import com.aliyuncs.iot.model.v20170420.ApplyDeviceWithNamesResponse;
import com.blkkj.huan.util.BaseTest;
import com.blkkj.huan.util.LogUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class applyDeviceWithNamesController extends BaseTest {

    @PostMapping("/applyDeviceWithNames")
    public String applyDeviceWithNames(String productKey, List<String> deviceNames){
        //批量注册设备
        Long applyId = applyDeviceWithNamesTest(productKey, deviceNames);
        try {
            Thread.sleep(1000L);
        } catch (Exception e) {
            LogUtil.error("exception:" + e.getMessage());
        }
        return "huan";
    }


    /**
     * 批量申请设备
     *
     * @param productKey 产品pk
     * @return 申请单id
     */
    public static Long applyDeviceWithNamesTest(String productKey, List<String> deviceNames) {
        ApplyDeviceWithNamesRequest request = new ApplyDeviceWithNamesRequest();
        request.setProductKey(productKey);
        request.setDeviceNames(deviceNames);
        ApplyDeviceWithNamesResponse response = (ApplyDeviceWithNamesResponse)executeTest(request);

        if (response != null && response.getSuccess() != false) {
            LogUtil.print("批量申请设备成功！ applyId: " + response.getApplyId());
            return response.getApplyId();

        } else {
            LogUtil.error("批量申请设备失败！requestId:" + response.getRequestId() + "原因：" + response.getErrorMessage());

        }
        return null;

    }
}
